<?php
if ( ! defined('BASEPATH')) exit('No direct script access allowed');
class Article_model extends CI_Model
{
    public $cid;
    public $atitle;
    public $adate;
    public $acontents;
    public $aid;
    public $aishot;

    public function __construct()
    {
        parent::__construct();
        $this->load->database();
    }

    public function Get_ArticleList_Page()
    {
        return $this->db->select()->from('article')->order_by('aishot', 'desc')->order_by('cid','asc')->where('aid>0')->get()->result();
    }
    public function Get_Article_Cate()
    {
        return $this->db->select()->from('artcate')->order_by('cid','asc')->where('cid>0')->get()->result_array();
    }

    public function Inset_Article()
    {
        return $this->db->insert('article',$this);
    }
    //Get_ArticleBy_Id
    public function Get_ArticleBy_Id($aid)
    {
        return $this->db->select()->from('article')->where(array('aid'=>$aid))->get()->result();
    }

    public function EditArticleBy($articleModel)
    {
        $this->db->update('article',$articleModel,array('aid'=>$articleModel->aid));
        return $this->db->affected_rows();
    }

    public function DelArticle_ById($aid)
    {
        $res= $this->db->delete('article',array('aid'=>$aid));
        return $this->db->affected_rows();
    }
    public function UsetArticle_Hot($articleId)
    {
        $this->db->update('article',array('aishot'=>0),array('aid'=>$articleId));
        return $this->db->affected_rows();
    }
    public function setArticle_Hot($articleId)
    {
        $this->db->update('article',array('aishot'=>1),array('aid'=>$articleId));
        return $this->db->affected_rows();
    }
}
?>